package com.mao.dao.voucher;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Component;

import com.mao.dao.BaseDAOHibernate;
import com.mao.model.voucher.ReturnDeliveryVoucher;

@Component("returnDeliveryVoucherDao")
public class ReturnDeliveryVoucherDao extends BaseDAOHibernate{
	
	public ReturnDeliveryVoucher saveReturnDeliveryVoucher(ReturnDeliveryVoucher rdv){
		getHibernateTemplate().saveOrUpdate(rdv);
		return rdv;
	}
	
	public String verifiyCanReturn(long proId,long orgId,long whId) {
		Session session = this.getSession();
		String hql = "FROM ProductDeliveryVoucher pdv where pdv.product.id=:pid and pdv.voucher.org.id=:oid and pdv.voucher.wareHouse.id=:whid";
		Query  query = session.createQuery(hql);
		query.setParameter("pid", proId);
		query.setParameter("oid", orgId);
		query.setParameter("whid", whId);
		List result = query.list();
		if(result.size() > 0){
			return "yes";
		}else{
			return "no";
		}
		
	}

}
